package com.zealfi.zxb.api.controller;

import com.alibaba.fastjson.JSON;
import com.zealfi.zxb.api.service.RedisService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by kuan at 2018-05-02 上午 10:23
 */
@RestController
@RequestMapping("test")
public class TestController {
    private static final Logger logger = LoggerFactory.getLogger(TestController.class);

    @Autowired
    private RedisService redisService;

    @RequestMapping("add")
    public void add(String key, String value) {
        if (StringUtils.isNotEmpty(key) && StringUtils.isNotEmpty(value)) {
            redisService.set(key, value, 600L);
        } else {
            logger.info("key:{} value:{}", key, value);
        }
    }

    @RequestMapping("get")
    public String get(String key) {
        if (StringUtils.isNotEmpty(key)) {
            return JSON.toJSONString(redisService.get(key));
        } else {
            logger.info("empty key");
        }

        return "empty key";
    }
}
